﻿using CTM.Web.Models.Input;
using CTM.Web.Models.View.Account;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace CTM.Web.Models.View.Role
{
    public class RoleViewModel
    {
        [StringLength(128)]
        public string Id { get; set; }

        [Required(ErrorMessage = "*")]
        [Display(Name = "Role")]
        [StringLength(256)]
        public string Name { get; set; }

        [Display(Name = "Old role")]
        public string OriginalName { get; set; }

        public string SelectedUsers { get; set; }
        public IEnumerable<AssociateViewModel> CurrentUsers { get; set; }

        #region Constructors

        public RoleViewModel()
        {
            Permissions = new HashSet<Permission>();
            CurrentUsers = Enumerable.Empty<AssociateViewModel>();
        }

        public RoleViewModel(ApplicationRole role)
        {
            this.Id = role.Id;
            this.Name = role.Name;
            this.OriginalName = role.Name;
            this.Permissions = role.Permissions;
        }

        #endregion

        #region Relationship
        public virtual ICollection<Permission> Permissions { get; set; }
        #endregion
    }
}